package cn.yqn.web.controller;

import cn.yqn.exception.GlobalCustomException;
import cn.yqn.enums.GlobalEnumCode;
import cn.yqn.result.JSONResult;
import cn.yqn.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/verifycode")
@RestController
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * @Description: 图片验证码
     * @Author: Mr.She
     * @Version: 1.0
     * @Date:  2022/7/28 0:09
     */
    @GetMapping("/imageCode/{key}")
    public JSONResult getVerifyCode(@PathVariable("key") String key) {
        if(true) {
            String baseStr = verifyCodeService.getVerifyCode(key);
            return JSONResult.success(baseStr);
        } else {
            throw new GlobalCustomException(GlobalEnumCode.USER_USERNAME_ERROR);
        }
    }

    @GetMapping("/sendSmsCode/{mobile}")
    public JSONResult sendSmsCode(@PathVariable("mobile") String mobile){
        verifyCodeService.sendSmsCode(mobile);
        return JSONResult.success();
    }


}
